package concurrent;

import org.junit.jupiter.api.Test;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author: kejl
 * @create: 2020-10-14 12:43
 */
public class AtomicTest {

    @Test
   void test01(){
       AtomicInteger atomicInteger = new AtomicInteger(1);

       ExecutorService executorService = Executors.newFixedThreadPool(3);

       for (int i = 0; i <10 ; i++) {

           executorService.execute(new Runnable() {
               @Override
               public void run() {
                   atomicInteger.incrementAndGet();
                   System.out.println(atomicInteger.get());
               }
           });

       }


       //创建一个可重用固定个数的线程池 Executors.newFixedThreadPool(int n)
//       ExecutorService fixedThreadPool = Executors.newFixedThreadPool(3);
//       for (int i = 0; i < 10; i++) {
//           fixedThreadPool.execute(new Runnable() {
//               public void run() {
//                   try {
//                       //打印正在执行的缓存线程信息
//                       System.out.println(Thread.currentThread().getName()+"正在被执行");
//                       Thread.sleep(2000);
//                   } catch (InterruptedException e) {
//                       e.printStackTrace();
//                   }
//               }
//           });
//       }


    }
}
